﻿/*
 * This file is part of CommunitySettlers.
 *
 * CommunitySettlers is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * CommunitySettlers is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with CommunitySettlers.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Author: Christoph Husse
 * 
 * Also checkout our homepage: http://communitysettlers.codeplex.com/
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SettlersEngine
{
    internal class Settler : AutoPositionTranformable
    {
        private AnimatedElement m_Element;

        public IMovableObject Movable { get; private set; }

        public Settler(Exported.GameInstance inInstance, IMovableObject inMovable)
            : base(inInstance, inMovable)
        {
            Movable = inMovable;

            m_Element = new AnimatedElement()
            {
                Source = "SettlerIdle",
                Margin = new Thickness(10, 10, 0, 0),
                VerticalAlignment = System.Windows.VerticalAlignment.Top,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
            };

            m_Element.Play("Angle_180");
            Content = m_Element;

            Movable.OnDirectionChanged += Movable_OnDirectionChanged;
        }

        void Movable_OnDirectionChanged(IMovableObject inSender, Direction inOldValue, Direction inNewValue)
        {
            switch (inNewValue)
            {
                case Direction._000: m_Element.Play("Angle_000"); break;
                case Direction._045: m_Element.Play("Angle_045"); break;
                case Direction._090: m_Element.Play("Angle_090"); break;
                case Direction._135: m_Element.Play("Angle_135"); break;
                case Direction._180: m_Element.Play("Angle_180"); break;
                case Direction._225: m_Element.Play("Angle_225"); break;
                case Direction._270: m_Element.Play("Angle_270"); break;
                case Direction._315: m_Element.Play("Angle_315"); break;
            }
        }
    }
}
